package com.zeng.mvpdemo.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.zeng.mvpdemo.R;
import com.zeng.mvpdemo.presenter.LoginPresenter;
import com.zeng.mvpdemo.view.ILoginView;

public class LoginActivity extends MvpBaseActivity<ILoginView, LoginPresenter> implements ILoginView {

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter();
    }

    private EditText mNameEt, mPwdEt;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        mNameEt = getView(R.id.login_et_name);
        mPwdEt = getView(R.id.login_et_pwd);
        getView(R.id.login_btn_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = mNameEt.getText().toString().trim();
                String pwd = mPwdEt.getText().toString().trim();
                if (TextUtils.isEmpty(name) || TextUtils.isEmpty(pwd)) {
                    toast("请填写完整信息");
                    return;
                }
                mPresenter.login(LoginActivity.this, name, pwd);
            }
        });
    }


    @Override
    public void onLoginResult(boolean success, String errMsg) {
        if (success) {
            toast("登录成功");
            Intent it = new Intent();
        } else {
            toast(errMsg);
        }
    }
}
